package com.bridge.client.bridgedynamcclient.custom_compinents;

import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class ProgressDialog extends Dialog<Void> {

    private ProgressIndicator progress;
    private Label progressLabel;

    public ProgressDialog() {
        this("处理中...");
    }

    public ProgressDialog(String msg) {
        this(msg, false);
    }

    public ProgressDialog(String msg, boolean closeAble) {
        setTitle("提示");
        initStyle(StageStyle.UNDECORATED);
        initModality(Modality.APPLICATION_MODAL);

        VBox dialogVbox = new VBox();
        dialogVbox.setMinWidth(150);
        dialogVbox.setSpacing(15);
        dialogVbox.setAlignment(Pos.TOP_CENTER);

        progress = new ProgressIndicator(0);
        progress.setProgress(-1);
        progressLabel = new Label(msg);

        dialogVbox.getChildren().addAll(progress, progressLabel);
        getDialogPane().setContent(dialogVbox);
        //getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
    }

    public void closeDialog(){
       // this.close();
        // 获取对话框的窗口
        Stage dialogStage = (Stage) this.getDialogPane().getScene().getWindow();
        dialogStage.close();
    }

}
